package extras.salvation.api.methods;

import com.rsbuddy.script.methods.Players;
import com.rsbuddy.script.wrappers.Area;
import com.rsbuddy.script.wrappers.Player;
import com.rsbuddy.script.wrappers.Tile;

/**
 * @author Salvation
 * @version 1.0
 * @since 20-08-2011
 */
public final class ExtendedAreas {

	/**
	 * @author Salvation
	 * @param area The Area to check.
	 * @return <tt>true</tt> if the LocalPlayer is within this Area, otherwise <tt>false</tt>.
	 */
	public static boolean atArea(final Area area) {
		if (area == null) return false;
		final Player p = Players.getLocal();
		if (p == null) return false;
		return area.contains(p.getLocation());
	}

	/**
	 * @author Salvation
	 * @param areas The Areas to check.
	 * @return <tt>true</tt> if the LocalPlayer is within either of these Areas, otherwise <tt>false</tt>.
	 */
	public static boolean atArea(final Area[] areas) {
		if (areas == null) return false;
		final Player p = Players.getLocal();
		if (p == null) return false;
		for (final Area a : areas) {
			if (a.contains(p.getLocation())) {
				return true;
			}
		}
		return false;
	}

	/**
	 * @author Salvation
	 * @param area The Area to check.
	 * @param tile The Tile to check.
	 * @return <tt>true</tt> if this Area contains this Tile, otherwise <tt>false</tt>.
	 */
	public static boolean atArea(final Area area, final Tile tile) {
		if (area == null || tile == null) return false;
		return area.contains(tile);
	}

	/**
	 * @author Salvation
	 * @param area The Areas to check.
	 * @param tile The Tile to check.
	 * @return <tt>true</tt> if either of these Areas contain this Tile, otherwise <tt>false</tt>.
	 */
	public static boolean atArea(final Area[] areas, final Tile tile) {
		if (areas == null || tile == null) return false;
		for (final Area a : areas) {
			if (atArea(a, tile)) {
				return false;
			}
		}
		return false;
	}
}